package com.liww.resource;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.core.Context;

import org.apache.log4j.Logger;
import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;

public abstract class AbstractCRUDResource {
	protected static final Logger logger = Logger.getLogger(AbstractCRUDResource.class);
		
	@Context
	protected HttpServletRequest request;
	@Context
	protected HttpServletResponse response;
	/**
	 * 对象转换成JSON字符串方法
	 * @param obj
	 * @return
	 */
	protected static String writeValueAsString(Object obj)
	{
		String result = "";
		try {
			result = new ObjectMapper().writeValueAsString(obj);
		} catch (JsonGenerationException e) {
			logger.error(e);
			e.printStackTrace();
		} catch (JsonMappingException e) {
			logger.error(e);
			e.printStackTrace();
		} catch (IOException e) {
			logger.error(e);
			e.printStackTrace();
		}
		return result;
	}
	
	}